#include "ui_debug.h"
#include "lvgl.h"
#include "stdarg.h"

#define UI_DEBUG_SIZE (256)

static char ui_debug_buf[UI_DEBUG_SIZE + 1] = {0};
static ui_debug_dis_width = 0;

static lv_obj_t *ui_debug_label;

void ui_debug_init(void)
{
    lv_obj_t *src = lv_scr_act();
    ui_debug_dis_width = lv_obj_get_width(src);
    ui_debug_label = lv_label_create(src, NULL);
    lv_label_set_long_mode(ui_debug_label, LV_LABEL_LONG_BREAK);
    lv_obj_set_width(ui_debug_label, ui_debug_dis_width);
    lv_label_set_align(ui_debug_label, LV_LABEL_ALIGN_LEFT);
    lv_label_set_static_text(ui_debug_label, ui_debug_buf);
}

void ui_debug(char *format, ...)
{
    va_list arg;
    va_start(arg, format);
    vsnprintf(ui_debug_buf, UI_DEBUG_SIZE, format, arg);
    lv_label_set_static_text(ui_debug_label, ui_debug_buf);
}
